<!DOCTYPE html>
<html>

<head>
    <title>KDT - Delivery system</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <script src="/kdt.js"></script>
    <script type="text/javascript">
    function login_me() {
        var xhr = new XMLHttpRequest()
        xhr.onload = function(e) {
            if (this.status == 200 || this.status == 304) {
                var o = JSON.parse(xhr.responseText)
                if (o.State == 'OK') {
                    setCookie('KDT-User-Sid', o.Info, 365)
                    setCookie("KDT-Mode", "User", 365)
                    setCookie('KDT-User-Phone', document.getElementById("form_phone").value, 365)
                    location.href = '/'
                } else if (o.State == 'ERR') {
                    if (o.Info == 'not found') {
                        alert("User doesn't exists, register please .")
                    }
                } else {
                    alert(o.Info)
                }
            }
        }
        xhr.open("POST", "/apis/user/login", true)
        var obj = new Object()
        obj.Phone = document.getElementById("form_phone").value
        obj.Password = document.getElementById("form_password").value
        // document.getElementById('result').innerHTML=JSON.stringify(obj)
        xhr.send(JSON.stringify(obj))
    }
    </script>
</head>

<body style="display: flex;flex-direction: column;align-items: center;background-color: #FF6D00">
    <span style="display: inline;color: #fff;font-size: 50px;">淘宝商城</span>
    <br>
    <div>
        <br>
        <br>
        <input type="number" name="phone" id="form_phone" placeholder="手机号">
        <br>
        <br>
        <input type="password" name="password" placeholder="密码" id="form_password" onkeyup="if(event.keyCode==13){login_me()}">
        <br>
        <br>
        <div style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
            <input type="button" value="登陆" name="login" onclick="login_me()">
            <a href="/userRegister.html" style="color: #eee">注册</a>
        </div>
        <br>
        <br>
        <a href="/adminLogin.html" style="color: #222">商家登陆</a>
        <br>
        <br>
        <div id="result"></div>
    </div>
</body>

</html>